<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
<form id="editform" name="editform" class="form-horizontal" method="post"
	  action="${pageContext.request.contextPath}/resident/editEntity.shtml" enctype="multipart/form-data">
	<input type="hidden" class="form-control checkacc" value="${resident.id}"
		   name="id" id="id">
	<section class="panel panel-default">
		<div class="panel-body">
			<div class="form-group">
				<label class="col-sm-3 control-label">标题</label>
				<div class="col-sm-9">
					<input type="text" class="form-control " placeholder="请输入标题"
						   name="title" id="title" value="${resident.title}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">图片</label>
				<div class="col-sm-9">
					<input type="file" class="form-control " placeholder="请输上传轮播图片"
						   name="img" id="img" accept="image/*">
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-9 col-sm-offset-3">
					<a href="${imgHost}/${resident.imgUrl}" target="_blank"><img src="${imgHost}/${resident.imgUrl}" style="width: 50px;" /></a>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">类型</label>
				<div class="col-sm-9">
					<select class="form-control "  id="type" name="type" onchange="changeType(this)">
						<option value="">-----类型-----</option>
						<option value="NEWS">信息</option>
						<option value="ACTIVITY">活动</option>
						<option value="OTHER">外部链接</option>
						<option value="STATIC">静态展示</option>
					</select>
				</div>
			</div>
			<div class="form-group" id="activityBox" style="display: none;">
				<label class="col-sm-3 control-label">活动</label>
				<div class="col-sm-9">
					<select class="form-control " id="activity" name="activity">
						<option value="">-----活动-----</option>
						<c:forEach var="activity" items="${activityList}">
							<option value="${activity.id}">${activity.activityName}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group" id="infoBox" style="display: none;">
				<label class="col-sm-3 control-label">信息</label>
				<div class="col-sm-9">
					<select class="form-control " id="info" name="info">
						<option value="">-----信息-----</option>
						<c:forEach var="info" items="${infoList}">
							<option value="${info.id}">${info.title}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group" id="urlBox" style="display: none;">
				<label class="col-sm-3 control-label">链接地址</label>
				<div class="col-sm-9">
					<input type="url" class="form-control " value="${resident.url}" placeholder="链接，如:http://www.baidu.com"
						   name="url" id="url">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">排序</label>
				<div class="col-sm-9">
					<input type="number" class="form-control " value="${resident.sort}" placeholder="排序，数字越小越靠前"
						   name="sort" id="sort">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否上线</label>
				<div class="col-sm-9">
					<label class="inline"><input id="id-button-borders" checked="checked" onclick="checkstate(this)" type="checkbox" class="ace ace-switch ace-switch-6"><span class="lbl middle"></span></label>
					<input type="hidden"
						   name="status" id="status" value="Y">
				</div>
			</div>
		</div>
		<%@include file="/common/buttom.jspf"%>
	</section>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/hxsq/resident/edit.js"></script>
<script type="text/javascript">
	$("#type").val("${resident.type}");
	$("#info").val("${resident.targetId}");
	$("#activity").val("${resident.targetId}");

	function changeType(me){
		$("#activityBox,#infoBox,#urlBox").hide();
		$("#activityBox,#infoBox,#urlBox").val("");
		var v = me.value;
		if(v == "NEWS"){
			$("#infoBox").show();
		}else if (v == "ACTIVITY"){
			$("#activityBox").show();
		}else if (v == "OTHER"){
			$("#urlBox").show();
		}else if (v == "STATIC"){
		}
	}
	changeType(document.getElementById("type"));
	function checkstate(obj){
		if(obj.checked){
			$("#status").val("Y")
		}else{
			$("#status").val("N")
		}
	}
</script>